<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试登录注册和数据库</title>
    <script src="../api/index.js"></script>
</head>
<body>
    <h1>测试登录注册和数据库</h1>
    <input type="text" name="username" id="username" placeholder="请输入用户名">
    <input type="password" name="password" id="password" placeholder="请输入密码">
    <input type="submit" value="登录" onclick="login()">
    <input type="submit" value="注册" onclick="register()">
    <script>
        const getData = () => {
            const username = document.getElementById('username').value
            const password = document.getElementById('password').value
            return {
                username,
                password
            }
        }
        const register = () => {
            const data = getData()
            api({
                method: 'POST',
                url: '/register',
                data
            }).then(res => {
                console.log('测试注册:>>> ', res)
            })
        }
        const login = () => {
            const data = getData()
            api({
                method: 'POST',
                url: '/login',
                data
            }).then(res => {
                console.log('测试登录:>>> ', res)
            })
        }
    </script>
</body>
</html>